package lc.q51_100;

import java.util.HashMap;
import java.util.Map;

public class Q91 {

    public int numDecodings(String s) {
        // 动态规划处理
        if (s.length() == 0) {
            return 0;
        }
        int[] len = new int[s.length() + 1];
        len[0] = 1;
        for (int i = 0; i < s.length(); i++) {
            int ll = 0;
            if (s.charAt(i) != '0') {
                ll += len[i];
            }
            // 如果i大于等于1
            if (i >= 1 && s.charAt(i - 1) != '0') {
                String substring = s.substring(i - 1, i + 1);
                int i1 = Integer.parseInt(substring);
                if (i1 > 0 && i1 <= 26) {
                    ll += len[i - 1];
                }
            }
            len[i + 1] = ll;
        }
        return len[s.length()];
    }

    public static void main(String[] args) {
        System.out.println(new Q91().numDecodings("27"));
        System.out.println(new Q91().numDecodings("1212"));
    }
}
